package aad.storyboard.model;

import aad.storyboard.controller.GUIComposer;
import aad.storyboard.transitions.SlideTransition;
import android.app.Activity;
import android.content.Context;
import android.graphics.BlurMaskFilter;
import android.graphics.Color;
import android.graphics.Paint;
import android.os.Handler;
import android.view.View;
import android.webkit.WebView;
import android.widget.Toast;
import android.widget.ViewFlipper;

public class InfoAnimation extends Animation{
	
	//violates the MVC, might need to transfer to controller!
	//only implemented using toasts, view with ontouchlistener might be better
	//TODO stop storytimer 
	
		
	static ViewFlipper flipper; 
	private static Handler mHandler=new Handler();
	private Image currentImage;
	 
	private View wikiView;	
	private  String text;
	private static Activity activity;
	private boolean touched;
	
	public InfoAnimation(int start, int duration, Activity a){
		super(duration, start);
		flipper=GUIComposer.getInstance().getFlipper();	
		activity=a;
		this.text=text;
		
	}
	
	@Override
	public void animate() {
			
				
		 if (touched)
		{
			 BlurMaskFilter blurMaskFilter = new BlurMaskFilter(10,BlurMaskFilter.Blur.OUTER);

		     Paint paint = new Paint();
		     paint.setMaskFilter(blurMaskFilter);
		     paint.setColor(Color.RED);

		     currentImage.getBlurPaint().set(paint);	    
			
		     showExplanation(text);
		     touched=false;
		}
		
		
	}

	@Override
	public void adjustParameters() {
		// TODO Auto-generated method stub
		
	}
	
	public void showExplanation(String word)
    {   
    	String file="file:///android_asset/"+word+".html";
    	
    	wikiView=GUIComposer.getInstance().getWikiView();		
    	((WebView)wikiView).loadUrl(file);        
        
        mHandler.removeCallbacks(mTransitionTask);	    	
	    mHandler.postDelayed(mTransitionTask, 100);		    
        	    	
    
    }
    
    private static Runnable mTransitionTask = new Runnable() {
		   @Override
		public void run() {	
			   System.out.println("Slide Transition triggered");
			   SlideTransition t=new SlideTransition(300, 1000, flipper, activity);
			   flipper.setDisplayedChild(2);
			   flipper.invalidate();
		   }
		};

	public void setText(String name) {
		text=name;
		
	}

	public void setCurrentImage(Image img) {
		this.currentImage=img;
		
	}
	
	public void setTouched(boolean t)
	{
		touched=t;
	}
	

}
